package com.atfzr.LockSupport;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author 望夜
 * @date 2023/8/23---22:20
 */
public class LockSupportDemo {
    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
//            synchronized (objectLock) {
                System.out.println(Thread.currentThread().getName() + "\t ---------come in");
//                try {
//                    objectLock.wait();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
                LockSupport.park();
                System.out.println(Thread.currentThread().getName() + "\t ---------被唤醒");
//            }
        }, "t1");
        t1.start();

        //暂停几秒钟线程
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
//            synchronized (objectLock){
//                objectLock.notify();
//                System.out.println(Thread.currentThread().getName() + "\t ---------发出通知" );
//            }
            LockSupport.unpark(t1); //给t1发通行证 ，有 TODO
            System.out.println(Thread.currentThread().getName() + "\t ---------发出通知");
            },"t2").start();

    }
}
